/**
 *  @file MemoryStream.h
 */
#ifndef _MEMORYSTREAM_H_
#define _MEMORYSTREAM_H_

#include "Stream.h"

namespace cppflib
{

namespace collections { class BinBuf; }

namespace io
{

/**
 *  A stream residing in memory
 */
class _DLLAPI MemoryStream :public Stream
{
private:
    collections::BinBuf *pBinBuf;
    ptr_t rwPos;

public:
    MemoryStream(void);
    explicit MemoryStream(collections::BinBuf *pBinBuf);
    virtual ~MemoryStream(void);

    virtual void Close();
    virtual void Flush();
    virtual sz_t CanReadNoBlocking();
    virtual int Read(collections::ArrayByte &buffer);
    virtual int Read(collections::ArrayByte &buffer, int offset, int count);
    virtual int Read();   
    virtual i64_t Seek(i64_t offset, seekorigin_t origin);
    virtual int Write(collections::ArrayByte &buffer);
    virtual int Write(collections::ArrayByte &buffer, int offset, int count);
    virtual bool Write(u8_t val);

    void ResetPointer();
    void ResetPointerAndClearBuffer();
    sz_t GetBufferSize();
};

} // end of namespace io

} // end of namespace cppflib

#endif
